package pl.mcnova.model.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "contractors")
public class Contractor implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3493933945569450299L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

	private String city;

	private String contractorType;

	private String email;

	private String houseNumber;

	private String name;

	private String nip;

	private String status;

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "contractor", fetch = FetchType.EAGER)
	@JoinColumn(name = "Contractor_Id")
	private List<PhoneNumber> phones = new ArrayList<PhoneNumber>();

	private String postalCode;

	private String street;

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "contractor", fetch = FetchType.LAZY)
	@JoinColumn(name = "Contractor_Id")
	private List<Device> devices = new ArrayList<Device>();

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "contractor", fetch = FetchType.LAZY)
	@JoinColumn(name = "Contractor_Id")
	private List<Mail> mails = new ArrayList<Mail>();

	private String www;

	private String comments;

	public Contractor() {

	}

	public Contractor(String city, String type, String email, String houseNumber, String name, String nip,
			String status, List<PhoneNumber> phones, String postalCode, String street, List<Device> devices,
			String www, String comments) {
		setCity(city);
		setContractorType(type);
		setDevices(devices);
		setEmail(email);
		setHouseNumber(houseNumber);
		setName(name);
		setNip(nip);
		setStatus(status);
		setPhones(phones);
		setPostalCode(postalCode);
		setStreet(street);
		setWww(www);
		setComments(comments);

	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCity() {
		return city;
	}

	public void setContractorType(String contractorType) {
		this.contractorType = contractorType;
	}

	public String getContractorType() {
		return contractorType;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setNip(String nip) {
		this.nip = nip;
	}

	public String getNip() {
		return nip;
	}

	public void setPhones(List<PhoneNumber> phones) {
		this.phones = phones;
	}

	public List<PhoneNumber> getPhones() {
		return phones;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getStreet() {
		return street;
	}

	public void setDevices(List<Device> devices) {
		this.devices = devices;
	}

	public List<Device> getDevices() {
		return devices;
	}

	public void setWww(String www) {
		this.www = www;
	}

	public String getWww() {
		return www;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getStatus() {
		return status;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getComments() {
		return comments;
	}

	public void setHouseNumber(String houseNumber) {
		this.houseNumber = houseNumber;
	}

	public String getHouseNumber() {
		return houseNumber;
	}

	public void setMails(List<Mail> mails) {
		this.mails = mails;
	}

	public List<Mail> getMails() {
		return mails;
	}

	@Override
	public String toString() {
		if (name != null) return name;
		return "";
	}

}
